import 'package:flutter/material.dart';
import 'package:flutter_baselib/lib.dart';
import 'package:flutter_baselib_example/module/login/view_model/login_view_model.dart';
import 'package:flutter_baselib_example/module/userlist/view/user_list_view.dart';

///@date:  2021/3/1 12:00
///@author:  lixu
///@description: 登录页
class LoginView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('登录'),
      ),
      body: ChangeNotifierProvider(
        create: (_) {
          return LoginViewModel();
        },
        child: Consumer<LoginViewModel>(
          builder: (_, viewModel, child) {
            return Column(
              children: [
                Text(
                  '登录信息：\n${viewModel.loginResultBean?.toString() ?? '未登录'}',
                ),
                RaisedButton(
                  child: Text('登录（http获取单个对象）'),
                  onPressed: () async {
                    bool isSuccess = await viewModel.onLogin(context);
                    if (isSuccess) {
                      return Navigator.push(context, MaterialPageRoute(builder: (context) {
                        return UserListView();
                      }));
                    }
                  },
                ),
                RaisedButton(
                  child: Text('获取用户列表（http获取List对象）'),
                  onPressed: () async {
                    viewModel.getUserList(context);
                  },
                ),
              ],
            );
          },
        ),
      ),
    );
  }
}
